package com.hongyue.Dey02;

import java.util.ArrayList;
import java.util.Collections;

public class ZhenKuaiPai {
    public static void main(String[] args) {
        ArrayList<Integer> arr = new ArrayList<>();
        Collections.addAll(arr, 10, 5, 7, 4, 3);
        kuaipai(arr, 0, arr.size() - 1);
        System.out.println("arr = " + arr);
    }

    private static void kuaipai(ArrayList<Integer> arr, int t, int w) {
        if (t > w) {
            return;
        }
        int t1 = t;
        int w1 = w;
        int qi = arr.get(t);
        while (t1 != w1) {
            while (arr.get(w1) >= qi && w1 != t1) {
                w1--;
            }
            while (arr.get(t1) <= qi && w1 != t1) {
                t1++;
            }
            int i = arr.get(w1);
            arr.set(w1, arr.get(t1));
            arr.set(t1, i);
        }
        int i = arr.get(w1);
        arr.set(w1, qi);
        arr.set(t, i);

        kuaipai(arr, t, w1 - 1);
        kuaipai(arr, w1 + 1, w);
    }
}
